import Vue from 'vue'
const focus = {
  install (Vue, options) {
    Vue.directive('focus', {
      inserted: (el, binding, vnode) => {
        el.focus()
      }
    })
  }
}

const focusBlur = {
  install (Vue, options) {
    Vue.directive('focus-blur', {
      componentUpdated: (el, binding, vnode) => {
        function blurDom (nodeList) {
          for (let node of nodeList) {
            node.onfocus = (e) => {
              if (node.blur) {
                node.blur()
              }
            }
            if (node.hasChildNodes()) {
              blurDom(node.childNodes)
            }
          }
        }
        blurDom([el])
      }
    })
  }
}

Vue.use(focus)
Vue.use(focusBlur)
